package com.arpa.oms.controller;


import com.arpa.core.web.Result;
import com.arpa.ntocc.common.common.Page;
import com.arpa.ntocc.common.common.constant.StrConsts;
import com.arpa.ntocc.common.common.util.UserUtil;
import com.arpa.ntocc.common.controller.BaseController;
import com.arpa.ntocc.common.security.annotation.NeedLogin;
import com.arpa.oms.domain.dto.OmsGoodsRelationRecordDTO;
import com.arpa.oms.domain.vo.OmsGoodsRelationRecordVO;
import com.arpa.oms.service.IOmsGoodsRelationRecordService;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * <p>
 * OMS商品关系记录 Controller
 * </p>
 *
 * @author rfwang
 * @since 2021-08-10
 */
@Api(tags = "OMS商品关系记录")
@RestController
@RequestMapping(value="/oms/omsGoodsRelationRecord", produces = "application/json;charset=UTF-8")
@Log4j2(topic = "business")
public class OmsGoodsRelationRecordController extends BaseController {

    @Autowired
    private IOmsGoodsRelationRecordService omsGoodsRelationRecordService;
    /**
     * 获取 商品关系记录 列表
     *
     * @param omsGoodsRelationRecordDTO
     * @param request
     * @return
     */
    @ApiOperation(value = "获取 商品关系记录 列表", notes = "获取 商品关系记录 列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "授权token", required = true, paramType = "header", dataType = "String", defaultValue = "Bearer "),
            @ApiImplicitParam(name = "deviceId", value = "设备id", paramType = "header", dataType = "string", defaultValue = "0000000000")
    })
    @ApiResponses(@ApiResponse(code = 0, message = "success", response = OmsGoodsRelationRecordVO.class))
    @NeedLogin
    @GetMapping()
    public Result list(OmsGoodsRelationRecordDTO omsGoodsRelationRecordDTO, HttpServletRequest request) {
        try {
            omsGoodsRelationRecordDTO.setShipmentCode(UserUtil.getLoginWarehouseCodeOrShipmentCode());
            OmsGoodsRelationRecordVO omsGoodsRelationRecordVOSum = omsGoodsRelationRecordService.queryListSum(omsGoodsRelationRecordDTO);
            List<OmsGoodsRelationRecordVO> omsGoodsRelationRecordVOList = omsGoodsRelationRecordService.queryList(omsGoodsRelationRecordDTO);

            Page returnPage = new Page(omsGoodsRelationRecordDTO.getPageNum(),omsGoodsRelationRecordDTO.getPageSize());
            returnPage.setRecords(omsGoodsRelationRecordVOList);
            returnPage.setTotal(omsGoodsRelationRecordVOSum.getTotal());
            returnPage.setSumObject(omsGoodsRelationRecordVOSum);
            return Result.ok().data(returnPage);
        } catch (Exception e) {
            log.error(StrConsts.CATCH_MESSAGE,e);
            return Result.error(e.getMessage());
        }
    }

 }
